package com.sf.dlb.service;

import com.sf.dlb.constant.ResponseConstant;
import com.sf.dlb.jpa.model.AppConfigInfo;
import com.sf.dlb.jpa.repository.AppConfigRepository;

import com.sf.dlb.utils.ResultVOUtil;
import com.sf.dlb.vo.AppConfigVO;
import com.sf.dlb.vo.ResultVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;

/**
 * Created by jing.tan on 2018/5/21.
 */
@Service
public class AppConfigService {
    private static Logger logger = LoggerFactory.getLogger(AppConfigService.class);
    @Autowired
    private AppConfigRepository appConfigRepository;
    /**
     * APP配置
     * @return
     */
    public ResultVO appConfig(){
        logger.info(" appConfig start ");
        List<AppConfigInfo> appConfigInfos= appConfigRepository.findByAppTypeAndDelFlag("2","0");
        if(CollectionUtils.isEmpty(appConfigInfos)){
            return ResultVOUtil.error(ResponseConstant.ERROR, "暂无APP配置");
        }
        AppConfigVO appConfigVO=new AppConfigVO();
        AppConfigInfo appConfigInfo=appConfigInfos.get(0);
        BeanUtils.copyProperties(appConfigInfo,appConfigVO);
        return ResultVOUtil.success(appConfigVO);
    }
}
